package org.demo.model.impl;

import org.demo.model.IModel;

public class QSaharaServer implements IModel {

	public static final String QSAHARA_SERVER = "QSaharaServer.exe";

	private final String server;
	private final String firehose;
	private final String port;

	private QSaharaServer(Builder builder) {
		this.server = builder.server;
		this.firehose = builder.firehose;
		this.port = builder.port;
	}

	public String getServer() {
		return server;
	}

	public String getFirehose() {
		return firehose;
	}

	public String getPort() {
		return port;
	}

	@Override
	public String cmd() {
		return new StringBuilder().append(getServer())
				.append(" -s ").append("13:").append(getFirehose())
				.append(" -p ").append("\\\\.\\").append(getPort())
				.toString();
	}

	public static class Builder {

		private String server;
		private String firehose;
		private String port;

		public Builder server(String server) {
			if (server == null || server.isEmpty() || !server.endsWith(QSAHARA_SERVER)) {
				throw new IllegalArgumentException("QSaharaServer can not access!!!");
			}
			if (server.contains(" ")) {
				this.server = "\"" + server + "\"";
			} else {
				this.server = server;
			}
			return this;
		}

		public Builder firehose(String firehose) {
			if (firehose == null || firehose.isEmpty()) {
				throw new IllegalArgumentException("firehose can not access!!!");
			}
			this.firehose = firehose;
			return this;
		}

		public Builder port(String port) {
			if (port == null || port.isEmpty() || !port.contains("COM")) {
				throw new IllegalArgumentException("port can not access!!!");
			}
			this.port = port;
			return this;
		}

		public QSaharaServer build() {
			return new QSaharaServer(this);
		}

	}
}
